/**
 * Copyright &copy; 2012-2016 <a href="https:github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.sys.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.SqlCondition;
import com.google.common.collect.Lists;
import com.thinkgem.jeesite.kpoint.core.base.KpointBaseEntity;
import com.thinkgem.jeesite.common.utils.Collections3;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.sys.SysConstants;
import lombok.Data;

import java.util.List;

/**
 * 通知通告Entity
 *
 * @author kongxiangsheng
 * @version 2014-05-16
 */
@Data
public class SysNotify extends KpointBaseEntity {
    public static final String COL_TYPE = "`type`";
    public static final String COL_TITLE = "`title`";
    public static final String COL_CONTENT = "`content`";
    public static final String COL_FILES = "`files`";
    public static final String COL_STATUS = "`status`";
    private static final long serialVersionUID = 1L;
    /**
     * 类型
     */
    private String type;
    /**
     * 标题
     */
    @TableField(condition = SqlCondition.LIKE)
    private String title;
    /**
     * 类型
     */
    private String content;
    /**
     * 附件
     */
    private String files;
    /**
     * 状态
     */
    private String status;
    /**
     * 已读条数
     */
    @TableField(exist = false)
    private String readNum;
    /**
     * 未读条数
     */
    @TableField(exist = false)
    private String unReadNum;

    /**
     * 是否已读
     */
    @TableField(exist = false)
    private String readFlag;

    /**
     * 记录
     */
    @TableField(exist = false)
    private List<SysNotifyRecord> sysNotifyRecordList = Lists.newArrayList();

    /**
     * 获取通知发送记录用户ID
     * @return
     */
    public String getRecordUserIds() {
        return Collections3.extractToString(sysNotifyRecordList, "userId", ",") ;
    }

    /**
     * 设置通知发送记录用户ID
     * @return
     */
    public void setRecordUserIds(String recordUserIds) {
        this.sysNotifyRecordList = Lists.newArrayList();
        for (String userId : StringUtils.split(recordUserIds, ",")){
            SysNotifyRecord record = new SysNotifyRecord();
            record.setUserId(userId);
            record.setReadFlag(SysConstants.NotifyReadFlag.UNREAD);
            this.sysNotifyRecordList.add(record);
        }
    }
}